package util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import model.Settings;

/**
 * @author it
 *
 */
public class CMYKtowebtool {
	private static CMYKtowebtool _instance;
	private Properties prop;
	
	
	private CMYKtowebtool()
	{
		prop = new Properties();
	}
	
	public static CMYKtowebtool getInstance()
	{
		if (_instance == null) {
			_instance = new CMYKtowebtool();
		}
		return _instance;
	}

	public Properties getProp() {
		return this.prop;
	}

	public void setProp(Properties prop) {
		this.prop = prop;
	}
	
	public void setValue(String key, String value)
	{
		this.getProp().setProperty(key, value);
		save();
	}
	
	public String getValue(String key)
	{
		load();
		return this.getProp().getProperty(key);
	}
	
	public void removeValue(String key)
	{
		this.getProp().remove(key);
		save();
	}
	
	public boolean isExists(String key)
	{
		load();
		return this.prop.containsKey(key);
	}
	
	public void save()
	{
		try
		{
			this.prop.store(new FileOutputStream(Settings.CMYKProperties), null);
		}
		catch(Exception e)
		{
			
		}
	}
	
	public void load()
	{
		try
		{
			this.prop.load(new FileInputStream(Settings.CMYKProperties));
		}
		catch(Exception e)
		{
			
		}
	}
	
	public static void main(String[] args)
	{
		CMYKtowebtool obj = CMYKtowebtool.getInstance();
		obj.setValue("name", "dmb");
		
		System.out.println(obj.isExists("name"));
	}
}
